package com.munchkinquest.utils;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 * String Utilities
 * @author stephen
 */
public class StringUtils {

    public static final int MAX_NOTE_LEN = 150;

    /**
     * Formats input src so it limits displayed text and puts full text in a 
     * tooltip popup using {@code popup()} from {@code popup.js}.
     * @param src
     * @return result
     */
    public static String getFormattedNote(String title, String body) {
        String result = "";
        //String displayed = body.length() > MAX_NOTE_LEN ? body.substring(0, MAX_NOTE_LEN) + "..." : body;
        String formatter = "<a href=\"#\" onMouseOver=\"stm(['%s','%s'],Style[2])\" onMouseOut=\"htm()\"><h3>%s</h3></a>";
        result = String.format(formatter, title, body.replaceAll("'", " "), title);
        return result;
    }

    public static void throwMessage(String message) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(message));
    }

}
